package servlets;

import entities.UserEntity;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 
 * @author andrei costache 
 *
 */
public class ContentFavoritesViewController extends ContentFavoritesController {

	@Override
	public void doRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

            RequestDispatcher view = null;
            String page = request.getParameter("page");
            HttpSession session = request.getSession();
            UserEntity user = (UserEntity)session.getAttribute("user");
            if (page != null) {
                Integer pg = new Integer(page);
                int[] range = new int[2];
                range[1] = pg * 10 - 1;
                range[0] = range[1] - 9;
                //will display only 10 results per

                request.setAttribute("contentList", favoritesDAO.findFullContentsByRange(range, user.getUid()));
            }
            else {
                request.setAttribute("contentList", favoritesDAO.findAllFullContents(user.getUid()));
            }

            //request.setAttribute("contentList")
            view = request.getRequestDispatcher("/jsp/ContentFavoritesView.jsp");
            view.forward(request, response);
	}
	
	

}
